package com.sunday.aomicaichang.ui.login;

import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.sunday.common.base.BaseActivity;
import com.sunday.common.utils.ToastUtils;
import com.sunday.aomicaichang.R;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by yun_sheng on 2017/5/31.
 */

public class RegisterTwoActivity extends BaseActivity {
    @Bind(R.id.edt_password)
    EditText edtPassword;
    @Bind(R.id.edt_confirm_password)
    EditText edtConfirmPassword;
    @Bind(R.id.btn_next)
    TextView btnNext;
    @Bind(R.id.see1)
    TextView see1;
    @Bind(R.id.see)
    TextView see;

    private String password, confirmPassword, code, phone;
    private boolean isSee = false;
    private boolean isSee1 = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register2);
        ButterKnife.bind(this);
        code = getIntent().getStringExtra("code");
        phone = getIntent().getStringExtra("phone");
        btnNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                password = edtPassword.getText().toString();
                confirmPassword = edtConfirmPassword.getText().toString();
                if (TextUtils.isEmpty(edtPassword.getText().toString())) {
                    ToastUtils.showToast(mContext, "密码不能为空！");
                    return;
                }
                if (TextUtils.isEmpty(edtConfirmPassword.getText().toString())) {
                    ToastUtils.showToast(mContext, "请输入确认密码！");
                    return;
                }
                if (!edtPassword.getText().toString().equals(edtConfirmPassword.getText().toString())) {
                    ToastUtils.showToast(mContext, "密码与确认密码不符！");
                    return;
                }

                // 要验证的字符串
//                String str = edtPassword.getText().toString();
//                // 正则表达式规则
//                String regEx = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$";
//                Pattern pattern = Pattern.compile(regEx);
//                // 忽略大小写的写法
//                // Pattern pat = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
//                Matcher matcher = pattern.matcher(str);
//                // 查找字符串中是否有匹配正则表达式的字符/字符串
//                final boolean rs = matcher.find();
//                if (rs) {
                    Intent intent = new Intent(mContext, RegisterThreeActivity.class);
                    intent.putExtra("code", code);
                    intent.putExtra("password", edtPassword.getText().toString());
                    intent.putExtra("phone", phone);
                    startActivity(intent);
//                } else {
//                    ToastUtils.showToast(mContext, "密码输入不符合规范！");
//                    return;
//                }
            }
        });
    }

    @OnClick({R.id.see,R.id.see1})
    void onClick(View v) {
        switch (v.getId()) {
            case R.id.see:
                see.setSelected(!isSee);
                isSee = !isSee;
                if (isSee) {
                    edtPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                } else {
                    edtPassword.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD| InputType.TYPE_CLASS_TEXT);
                }
                break;
            case R.id.see1:
                see1.setSelected(!isSee1);
                isSee1 = !isSee1;
                if (isSee1) {
                    edtConfirmPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                } else {
                    edtConfirmPassword.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD| InputType.TYPE_CLASS_TEXT);
                }
                break;
        }
    }
}
